/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mwt.xml.xdbforms.dblayer.metadata;

import java.sql.DatabaseMetaData;
import java.util.Collection;
import mwt.xml.xdbforms.dblayer.ConnectionFactory;
import mwt.xml.xdbforms.dblayer.query.Projections;
import mwt.xml.xdbforms.dblayer.query.Query;
import mwt.xml.xdbforms.dblayer.query.SQLOperation;
import mwt.xml.xdbforms.dblayer.query.exception.QueryException;
import mwt.xml.xdbforms.dblayer.query.impl.ProjectionsImpl;
import mwt.xml.xdbforms.dblayer.query.impl.SQLQuery;


/**
 * Classe astratta CatalogMetadata implementa
 * due interfacce : DatabaseMetaData (definita in Jdbc) e
 * DMBSDependedMetaData che definisce alcune metodi che
 * devono essere reimplementati a seconda del dbms da usare.
 * @see DatabaseMetaData
 * @see DBMSDependedMetaData
 * @author Gianfranco Murador, Cristian Castiglia, Matteo Ferri
 */
public abstract class CatalogMetaData implements DatabaseMetaData, DBMSDependedMetaData{


   

    /**
     * Chiude la connessione con la risorsa dati
     */
    public abstract void close();


    /**
     * Ottiene i valori delle chiavi esterne
     * @param colname
     * @param tablename
     * @return
     */
    
    public Collection getForeingKeyValue(String colname, String tablename){

        Collection c = null;
        ConnectionFactory cf = ConnectionFactory.getInstance();
        Query q = cf.getQuery();
        SQLOperation sqlo = new SQLQuery(tablename);
        Projections p = new ProjectionsImpl();
        p.property(colname);
        sqlo.addProjections(p);
        sqlo.compile();

        System.out.println("FOREIGN KEY SELECT    "+ sqlo.toString());


        try {
            
            c = q.read(sqlo);
            return c;
        } catch (QueryException ex) {
            ex.printStackTrace();
        }

        return c;

       

    }
    



    }
